package com.hhd.pdf.component;

import com.hhd.pdf.context.GeneratorContext;
import com.hhd.pdf.utils.PdfUtils;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TitleComponent extends AbstractPdfComponent {

    @Override
    public List<Element> doGenElements(GeneratorContext context) {
        org.dom4j.Element parsingElement = context.getParsingElement();
        GeneratorContext runtimeContext = context.runtime();
        Font font = PdfUtils.createFont(16, context.getGeneratorParameters().getColor(), Font.BOLD);
        runtimeContext.getGeneratorParameters().setFont(font);
        runtimeContext.getGeneratorParameters().setAlign(Paragraph.ALIGN_CENTER);
        return genChildren(runtimeContext, parsingElement);
    }

    @Override
    public String getName() {
        return "title";
    }
}
